home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Tasks / connect-end.cgi.z / connect-end.cgi
Encoding:
Text File  |  1997-07-30  |  24.0 KB  |  822 lines

  1. #!/usr/bin/perl5
  2. #
  3. # connect-end.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: connect-end.cgi,v 1.57 1997/06/19 22:26:42 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23.  
  24. if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.connect-start.cgi",10,10); } 
  25.  
  26. $myname = "connect-end.cgi?" . $ARGV[0];
  27. $temp = "task.tmp";
  28. $dummy = "task.dummy";
  29.  
  30. $passwd = "/etc/passwd";
  31. $isdnop = "/etc/config/isdnd.options";
  32. $sendmail = "/etc/sendmail.params";
  33. $hosts = "/etc/hosts";
  34. $resolv = "/etc/resolv.conf";
  35. $ppp = "/etc/ppp.conf";
  36. $ppp_config = "/etc/config/ppp.startup";
  37. $modem_file = "/usr/OnRamp/etc/modem.trans";
  38. $devices = "/etc/uucp/Devices";
  39. $systems = "/etc/uucp/Systems";
  40. $confW = "/etc/config/wsyncd.options";
  41. $init = "/etc/inittab";
  42.  
  43. $it = "<td colspan=60>";
  44. $ni = "</td>";
  45. $bo = "<td colspan=150><font size=5><i>";
  46. $nb = "</i></font></td>";
  47.  
  48. &get_fields;
  49.  
  50. if ($fld{'cancel'}) { 
  51.     $message = "Network configuration cancelled"; 
  52. } elsif ($fld{'accept'}) {
  53.     &configure;
  54.     #print "Location: /tasks/connect-epitath.cgi\n\n";
  55.     $go = "/tasks/connect-epitath.cgi";
  56.     print "Content-type: text/html\n\n";
  57.     print "<HTML><HEAD>";
  58.     print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
  59.     print "</HEAD><BODY></BODY></HTML>";
  60.     exit 0;
  61. }
  62.  
  63. &readValues;
  64.  
  65. &generic;
  66.  
  67. sub configure {
  68.     &readValues;
  69.  
  70.     open(IN, "/usr/bsd/hostname |");
  71.     $hostName = <IN>;
  72.     close(IN);
  73.     chop $hostName;
  74.     if ($hostName =~ /^([^\.]*)\./) { $hostName = $1; }
  75. #    ($name, $dummyb, $dummyc, $dummyd, @dummye) = gethostbyname($hostName);
  76. #    $name =~ /^\w+\.(.*)$/;
  77. #    $domainName = $1;
  78.  
  79.     $domainName = $terms{'domain'};
  80.  
  81.     # named
  82.     if (-e "/usr/sbin/named") {
  83.         open(IN,"/usr/OnRamp/bin/htnetwork | ");
  84.         $line = <IN>;
  85.         close(IN);
  86.         @items = split(/:/,$line);
  87.         $IPaddr = $items[3];
  88.         @parts = split(/\./,$IPaddr);
  89.         if ($parts[0] < 128) {    # class A
  90.             $rddan = $parts[0];
  91.             $rddahni = "$parts[3].$parts[2].$parts[1]";
  92.         }
  93.         elsif ($parts[0] < 192) {    # class B
  94.             $rddan = "$parts[1].$parts[0]";
  95.             $rddahni = "$parts[3].$parts[2]";
  96.         }
  97.         else {            # class C
  98.             $rddan = "$parts[2].$parts[1].$parts[0]";
  99.             $rddahni = $parts[3];
  100.         }
  101.     
  102.         @parts = split(/\./,$terms{'provider'});
  103.         if ($parts[0] < 128) {    # class A
  104.             $rddahxe = "$parts[3].$parts[2].$parts[1]";
  105.         }
  106.         elsif ($parts[0] < 192) {    # class B
  107.             $rddahxe = "$parts[3].$parts[2]";
  108.         }
  109.         else {            # class C
  110.             $rddahxe = $parts[3];
  111.         }
  112.  
  113.         $nmd{'localhost.rev'} = "/var/named";
  114.         $nmd{'named.boot'} = "/etc";
  115.         $nmd{'named.hosts'} = "/var/named";
  116.         $nmd{'named.rev'} = "/var/named";
  117.         foreach $arg (keys(%nmd)) {
  118.             $fileIN = "/usr/OnRamp/etc/" . $arg;
  119.             open(IN,"< $fileIN");
  120.             open(OUT,"> $dummy");
  121.             while(<IN>) {
  122.                 $_ =~ s/HOSTNAME/$hostName/g;
  123.                 $_ =~ s/DOMAIN/$domainName/g;
  124.                 $_ =~ s/RDDAN/$rddan/g;
  125.                 $_ =~ s/INADDR/$IPaddr/g;
  126.                 $_ =~ s/EXADDR/$terms{'provider'}/g;
  127.                 $_ =~ s/RDDAHNI/$rddahni/g;
  128.                 $_ =~ s/RDDAHXE/$rddahxe/g;
  129.                 $_ =~ s/NSADDR/$terms{'nameserver'}/g;
  130.  
  131.                 print OUT $_;
  132.             }
  133.             close(IN);
  134.             close(OUT);
  135.             $fileOUT = $nmd{$arg} . "/" . $arg;
  136.             rename($dummy,$fileOUT);
  137.         }
  138.     system("/etc/chkconfig", "named", "off");
  139.     }
  140.  
  141.     # sendmail deamon
  142.     open(OUT,"> $sendmail");
  143.     print OUT "rootdomain:$domainName\n";
  144.     print OUT "directdomains:$domainName\n";
  145.     print OUT "forwarder:$terms{'mailserver'}\n";
  146.     close(OUT);
  147.  
  148.     # /etc/ppp.conf
  149.     $addLine = 1;
  150.     $rename = 0;
  151.     open(OUT,"> $dummy");
  152.     open(IN,"< $ppp");
  153.     while(<IN>) {
  154.         @items = split(/\s+/);
  155.         if ($items[0] eq 'ppp' && $items[1] eq 'add_route') {
  156.             @subItems = split(/=/,$items[2]);
  157.             if ($subItems[0] eq 'remotehost' && 
  158.                 $subItems[1] eq $terms{'provider'}) {
  159.                 $addLine = 0;
  160.             print OUT $_;
  161.             } else { $rename = 1; print OUT "# $_"; } 
  162.         } else { print OUT $_; }
  163.     }
  164.     close(IN);
  165.     close(OUT);
  166.     if ($rename) { rename($dummy,$ppp); }
  167.     
  168.     if ($addLine) {
  169.         open(IN,"< $ppp");
  170.         open(OUT,"> $dummy");
  171.         $found = 0;
  172.         while(<IN>) {
  173.             $line = $_;
  174.             @items = split(/\s+/,$line);
  175.             if ($found == 0 && $items[1] eq 'Add' && $items[2] eq 'actual') {
  176.                 $found = 1;
  177.                 print OUT "$line\n";
  178.                 print OUT "ppp\t\tadd_route ";
  179.                 print OUT "remotehost=",$terms{'provider'},"\n\n";
  180.             } else { print OUT $line; }
  181.         }
  182.         if (!$found) {
  183.             print OUT "\nppp\t\tadd_route ";
  184.             print OUT "remotehost=",$terms{'provider'},"\n";
  185.         }
  186.         close(IN);
  187.         close(OUT);
  188.         rename($dummy,$ppp);
  189.     }
  190.  
  191.     # create ppp startup script
  192.     if (! -e "/etc/init.d/pppstartup") {
  193.         system("/sbin/cp", "/usr/WebFace/lib/S75pppstartup", 
  194.             "/etc/init.d/pppstartup");
  195.     }
  196.     if (! -l "/etc/rc2.d/S75pppstartup") {
  197.         system("/sbin/ln", "-s", "/etc/init.d/pppstartup", 
  198.             "/etc/rc2.d/S75pppstartup");
  199.     }
  200.  
  201.     if (-e $ppp_config) {
  202.     $add = 1;
  203.     open(IN, "< $ppp_config");
  204.     while(<IN>) {
  205.         if ($_ eq "ppp -r ppp\n") { $add = 0; }
  206.     }
  207.     close(IN);
  208.     if ($add) {
  209.         open(OUT,">> $ppp_config");
  210.         print OUT "ppp -r ppp\n";
  211.         close(OUT);
  212.     }
  213.     } else {
  214.     open(OUT, "> $ppp_config");
  215.     print OUT "# this file generated by gateway product\n";
  216.     print OUT "# sh file read by /etc/init.d/pppstartup\n\n";
  217.     print OUT "ppp -r ppp\n";
  218.     close(OUT);
  219.     }
  220.  
  221.     if (-e $ppp) { chmod 0600, $ppp; }
  222.  
  223.     # /etc/uucp/Systems
  224.     if ($terms{'phone'}) {
  225.         $phone = $terms{'phone'};
  226.         $phone =~ s/-//g;
  227.         $phone =~ s/\(//g;
  228.         $phone =~ s/\)//g;
  229.     }
  230.     if ($terms{'hardware'} eq 'ISDN') {
  231.         open(IN,"< $isdnop");
  232.         open(OUT,"> $dummy");
  233.         while(<IN>) {
  234.             $line = $_;
  235.             if (substr($_,0,2) ne "-t") { print OUT $_; }
  236.             else { print OUT "# $line"; }
  237.         }
  238.         print OUT "-t $terms{'switchtype'}";
  239.         if ($terms{'switchtype'} eq 'DMS100' || $terms{'switchtype'} eq 'NI1') {
  240.             print OUT " -s $terms{'spid1'} -s $terms{'spid2'}";
  241.         }
  242.         print OUT "\n";
  243.         close(OUT);
  244.         close(IN);
  245.         rename($dummy,$isdnop);
  246.  
  247.     system("/etc/chkconfig", "isdnd", "on");
  248.  
  249.         system("/bin/csh -c '(/bin/csh /etc/init.d/isdnd stop) >&! /dev/null'");
  250.         system("/bin/csh -c '(/bin/csh /etc/init.d/isdnd start) >&! /dev/null'");
  251.  
  252.         $addLine = 1;
  253.         $commentLine = 0;
  254.         open(IN,"< $systems");
  255.         while(<IN>) {
  256.             @items = split(/\s+/);
  257.             if ($items[0] eq 'ppp') {
  258.                 if (($items[6] eq 'ISDNCALL[56]' . $phone) ||
  259.                     ($items[6] eq 'ISDNCALL[64]' . $phone)) {
  260.                     $addLine = 0;
  261.                 } else {
  262.                     $commentLine = 1;
  263.                 }
  264.             }
  265.         }
  266.         close(IN);
  267.         if ($commentLine) {
  268.             @lst = ('ppp','Any','ISDN'); 
  269.             &comment($systems,*lst); 
  270.         }
  271.         if ($addLine) {
  272.             chmod 0600, $systems;
  273.             open(OUT,">> $systems");
  274.             if ($terms{'switchtype'} eq 'NET3') {
  275.                 print OUT 
  276.                 qq|\nppp Any ISDN 38400 "" "" ISDNCALL[64]$phone CONNECTED\n|;
  277.             } else {
  278.                 print OUT 
  279.                 qq|\nppp Any ISDN 38400 "" "" ISDNCALL[56]$phone CONNECTED\n|;
  280.             }
  281.             close(OUT); 
  282.             chmod 0400, $systems;
  283.         }
  284.     } elsif ($terms{'hardware'} eq 'Modem') {
  285.         $addLine = 1;
  286.         $commentLine = 0;
  287.         open(IN,"< $systems");
  288.         while(<IN>) {
  289.             @items = split(/\s+/);
  290.             if ($items[0] eq 'ppp') {
  291.                 if ($items[3] eq $terms{'speed'} && $items[4] eq $phone) {
  292.                     $addLine = 0;
  293.                 } else {
  294.                     $commentLine = 1;
  295.                 }
  296.             }
  297.         }
  298.         close(IN);
  299.         if ($commentLine) {
  300.             @lst = ('ppp','Any','ACU'); 
  301.             &comment($systems,*lst); 
  302.         }
  303.         if ($addLine) {
  304.             chmod 0600, $systems;
  305.             open(OUT,">> $systems");
  306.             print OUT "\nppp Any ACU $terms{'speed'} $phone in:--in: ";
  307.             print OUT "$terms{'lname'} word: $terms{'lpassword'}\n";
  308.             close(OUT); 
  309.             chmod 0400, $systems;
  310.         }
  311.  
  312.     } elsif ($terms{'hardware'} eq 'T1') {
  313.         $addLine = 1;
  314.         $commentLine = 0;
  315.         open(IN,"< $systems");
  316.         while(<IN>) {
  317.             @items = split(/\s+/);
  318.             if ($items[0] eq 'ppp') {
  319.                 if ($items[2] eq 'WAN') {
  320.                     $addLine = 0;
  321.                 } else {
  322.                     $commentLine = 1;
  323.                 }
  324.             }
  325.         }
  326.         close(IN);
  327.         if ($commentLine) {
  328.             @lst = ('ppp','Any','WAN'); 
  329.             &comment($systems,*lst); 
  330.         }
  331.         if ($addLine) {
  332.             chmod 0600, $systems;
  333.             open(OUT,">> $systems");
  334.             print OUT qq|ppp Any WAN - "" "" PPP CONNECTED\n|;
  335.             close(OUT); 
  336.             chmod 0400, $systems;
  337.         }
  338.     }
  339.  
  340.     # /etc/uucp/Devices
  341.     if ($terms{'hardware'} eq 'Modem') {
  342.         if ($terms{'speed'} > 2400) { $port = "ttyf"; }
  343.         else { $port = "ttym"; }
  344.         if ($terms{'port'} eq 'Port 1') { 
  345.             $port .= "1"; $prt = "1";
  346.             $dport = "ttyd1";
  347.         } else { 
  348.             $port .= "2"; $prt = "2";
  349.             $dport = "ttyd2";
  350.         }
  351.         $modem = &getModem($terms{'modem_type'});
  352.         open(OUT,">> $devices");
  353.         print OUT "ACU $port null $terms{'speed'} 212 x $modem\n";
  354.         print OUT "Direct $dport - Any direct\n";
  355.         close(OUT);
  356.  
  357.         $cmd = &hash_modem($terms{'modem_type'},1,3);
  358.         if ($cmd) { 
  359.             $cmd = "/etc/uucp/" . "$cmd $prt";
  360.             system("$cmd > /dev/null 2>&1");
  361.         } 
  362.     } elsif ($terms{'hardware'} eq 'T1') {
  363.         if ($terms{'port'} eq 'Port 1') { $dname = "/dev/gsc/wsty00"; }
  364.         else { $dname = "/dev/gsc/wsty01"; }
  365.         $rename = 0;
  366.         $found = 0;
  367.         open(IN,"< $devices");
  368.         open(OUT,"> $dummy");
  369.         while(<IN>) {
  370.             @items = split(/\s+/);
  371.             if ($items[0] ne 'WAN') { print OUT $_; next; }
  372.             if ($items[1] ne $dname) {
  373.                 print OUT "# $_";
  374.                 $rename = 1;
  375.                 $found = 1;
  376.                 print OUT qq|WAN $dname - - direct\n|;
  377.             } else { print OUT $_; $found = 1; }
  378.         }
  379.         if (!$found) {
  380.             print OUT qq|WAN $dname - - direct\n|;
  381.             $rename = 1;
  382.         }
  383.         close(IN);
  384.         close(OUT);
  385.         if ($rename) { rename($dummy,$devices); }
  386.     }    
  387.  
  388.     # /etc/inittab
  389.     if ($terms{'hardware'} eq 'Modem') {
  390.         $rename = 0;
  391.         if ($terms{'port'} eq 'Port 1') { $port = 1; }
  392.         else { $port = 2; }
  393.         open(IN,"< $init");
  394.         open(OUT,"> $dummy");
  395.         while(<IN>) {
  396.             @items = split(/:/);
  397.             if ($items[0] ne "t".$port) { print OUT $_; next; }
  398.             if ($items[2] ne "off") {
  399.                 $items[2] = "off";
  400.                 print OUT join(/:/,@items);
  401.                 $rename = 1;
  402.             }
  403.         }
  404.         close(OUT);
  405.         close(IN);
  406.         if ($rename) { rename($dummy,$init); }
  407.     }
  408.  
  409.     # /etc/resolv.conf
  410.     open(OUT,"> $resolv");
  411.     print OUT "search $domainName\n";
  412.     print OUT "hostresorder nis bind local\n\n";
  413.     print OUT "nameserver 0.0.0.0\n";
  414.     print OUT "nameserver $terms{'nameserver'}\n";
  415.     close(OUT);
  416.  
  417.     # T1
  418.     if ($terms{'hardware'} eq 'T1') {
  419.         if ($terms{'port'} eq 'Port 1') {
  420.             &turnOffPort(1);
  421.             &turnOnPort(0);
  422.         } else {
  423.             &turnOffPort(0);
  424.             &turnOnPort(1);
  425.         }
  426.  
  427.     system("/etc/chkconfig", "wsyncd", "on");
  428.     } else {
  429.     if (-e "/etc/config/wsyncd") {
  430.         system("/etc/chkconfig", "wsyncd", "off");
  431.        } 
  432.     }
  433.  
  434.     # ethernet (effects /etc/hosts and /etc/config/ifconfig-[n].options)
  435.     if ($terms{'hardware'} eq 'Ethernet') {
  436.         ($eth_type,$eth_label) = split(/ /,$terms{'interface'});
  437.         open(IN,"/usr/OnRamp/bin/htnetwork | ");
  438.         while(<IN>) {
  439.             @items = split(/:/);
  440.             if ($eth_type == $items[1]) {
  441.                 $oldIP = $items[3]; 
  442.                 $num = $items[0]; 
  443.             }
  444.         }
  445.         close(IN);
  446.         $num++;
  447.         $file = "/etc/config/ifconfig-" . $num . ".options";
  448.         open(OUT,"> $file");
  449.         print OUT "netmask $terms{'netmask'}\n";
  450.         close(OUT);
  451.  
  452.         open(IN,"hostname | ");
  453.         $hostname = <IN>; chop($hostname);
  454.         close(IN);
  455.  
  456.         if ($oldIP) { &removeHosts($oldIP); }
  457.         &addHosts($terms{'address'},"gate-".$hostname.".".$terms{'domain'});
  458.     system("/usr/etc/ifconfig", $eth_label, "inet", $terms{'address'},
  459.         "netmask", $terms{'netmask'});
  460.     }
  461.  
  462.     # tighten security
  463.     &nofreepass;
  464. }
  465.  
  466. sub nofreepass {
  467.     $PASSSOURCEFILE = "/etc/passwd";
  468.     $PASSWORKFILE = "/etc/passwd.tmp";
  469.     open(PASSWORDS, $PASSSOURCEFILE );
  470.     open(PASSOUT,   ">$PASSWORKFILE");
  471.  
  472.     while (<PASSWORDS>) {
  473.         split(/:/);
  474.         $_[1] = '*' if !$_[1] && $_[0] ne 'root';
  475.         print PASSOUT join(':' ,@_);
  476.     }
  477.  
  478.     close(PASSOUT);
  479.     close(PASSWORDS);
  480.  
  481.     rename($PASSWORKFILE,$PASSSOURCEFILE);
  482.     unlink $PASSWORKFILE;
  483. }
  484.  
  485. sub removeHosts {
  486.     local($rem_ip) = $_[0];
  487.     open(IN,"< $hosts");
  488.     open(OUT,"> $dummy");
  489.     while(<IN>) {
  490.         if (/^#/) {
  491.             print OUT $_;
  492.             next;
  493.         }
  494.         if (/^$rem_ip/) {
  495.             print OUT "# ".$_;
  496.             next;
  497.         }
  498.         print OUT $_;
  499.     }
  500.     close(OUT);
  501.     close(IN);
  502.     rename($dummy, $hosts);
  503. }
  504.  
  505. sub addHosts {
  506.     local($add_ip) = $_[0];
  507.     local($add_hs) = $_[1];
  508.     open(OUT,">> $hosts");
  509.     print OUT "$add_ip\t$addhs\n";
  510.     close(OUT);
  511. }
  512.  
  513. sub getModem {
  514.     $ret = "";
  515.     $key = $_[0];
  516.     open(IN,"< $modem_file");
  517.     while(<IN>) {
  518.         @items = split(/:/);
  519.         if ($key eq $items[1]) {
  520.             $ret = $items[0];
  521.             last;
  522.         }
  523.     }
  524.     close(IN);
  525.     return $ret;
  526. }
  527.         
  528. sub readValues {
  529.     open(IN,"< $temp");
  530.     while(<IN>) {
  531.         @items = split(/=/);
  532.         chop $items[1];
  533.         $terms{$items[0]} = $items[1];
  534.     }
  535.     close(IN);
  536. }
  537.  
  538. sub generic {
  539.     print "Content-type: text/html\n\n";
  540.     print "<html><head><title>Summary</title>\n";
  541.     print "<script language=\"JavaScript\">\n<!--\n";
  542.  
  543.     # JavaScript
  544. print "which = \"none\";
  545. function runSubmit() {
  546.     if(which == \"accept\") return (true);
  547.     if(which == \"cancel\") return runCancel();
  548.     return (true);
  549. }    
  550. function markAccept() { which = \"accept\"; }
  551. function markCancel() { which = \"cancel\"; }
  552. function runCancel()  {
  553.     setTimeout('window.location=\"/tasks/Tasks.connect-start.cgi?end\"',0);
  554.     return (false);
  555. }
  556. function Previous()  {
  557.     form = document.end;
  558.     if (form.prev.value == \"m\") { setTimeout('window.location=\"/tasks/connect-modem.cgi?end\"',0); }
  559.     if (form.prev.value == \"i\") { setTimeout('window.location=\"/tasks/connect-isdn.cgi?end\"',0); }
  560.     if (form.prev.value == \"t\") { setTimeout('window.location=\"/tasks/connect-t1.cgi?end\"',0); }
  561.     if (form.prev.value == \"e\") { setTimeout('window.location=\"/tasks/connect-ether-fddi.cgi?end\"',0); }
  562.     return;
  563. }\n";
  564.  
  565. print "//-->\n";
  566. print "</script></head>\n\n";
  567.  
  568.     print "<body bgcolor='c7ded4' background=/tasks/connect-task.bg.gif>\n";
  569.  
  570.     print "<i>$message</i>";
  571.  
  572.  
  573.     print "<table width=100%>",
  574.           "<tr><th align=left><h1>Summary</h1></th>\n",
  575.           "<th align=right><a href=\"/newsplash.shtml\">",
  576.           "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
  577.           "  <a href=\"/tasks/Tasks.shtml\">",
  578.           "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
  579.           "</tr></table>\n";
  580.  
  581. print "<br>
  582. Review the information that you entered in the Internet Gateway configuration
  583. forms:<br><br>\n\n";
  584.  
  585.     print "<center><table>\n";
  586.  
  587.     if ($terms{'hardware'} eq 'Ethernet or FDDI') {
  588.         @items = split(/\s+/,$terms{'interface'});
  589.         $outHardware = $items[0];
  590.         $outInterface = $items[1];
  591.     } else { $outHardware = $terms{'hardware'}; }
  592.  
  593.     print "<tr><td>Domain name:</td><td>$terms{'domain'}</td></tr>\n";
  594.     print "<tr><td>Provider address:</td><td>$terms{'provider'}</td></tr>\n";
  595.     print "<tr><td>Name server:</td><td>$terms{'nameserver'}</td></tr>\n";
  596.     print "<tr><td>Mail forwarder:</td><td>$terms{'mailserver'}</td></tr>\n";
  597.     print "<tr><td></td><td></td></tr>\n";
  598.     print "<tr><td>Hardware:</td><td>$outHardware</td></tr>\n";
  599.  
  600.     if ($terms{'hardware'} eq 'Modem') {
  601.         print "<tr><td>Port:</td><td>$terms{'port'}</td></tr>\n";
  602.         print "<tr><td>Modem type:</td><td>$terms{'modem_type'}</td></tr>\n";
  603.         print "<tr><td>Baud rate:</td><td>$terms{'speed'}</td></tr>\n";
  604.         print "<tr><td>Phone number:</td><td>$terms{'phone'}</td></tr>\n";
  605.         print "<tr><td>Login name:</td><td>$terms{'lname'}</td></tr>\n";
  606.         print "<tr><td>Login password:</td><td>$terms{'lpassword'}</td></tr>\n";
  607.     } elsif ($terms{'hardware'} eq 'ISDN') {
  608.         if ($terms{'switchtype'} eq 'NET3') {
  609.         print "<tr><td>Switch:</td><td>NET3/DSS1</td></tr>\n";
  610.         } else {
  611.         print "<tr><td>Switch:</td><td>$terms{'switchtype'}</td></tr>\n";
  612.         }
  613.         print "<tr><td>Phone number:</td><td>$terms{'phone'}</td></tr>\n";
  614.         if ($terms{'switchtype'} eq 'DMS100' || $terms{'switchtype'} eq 'NI1') {
  615.             print "<tr><td>SPID #1:</td><td>$terms{'spid1'}</td></tr>\n";
  616.             print "<tr><td>SPID #2:</td><td>$terms{'spid2'}</td></tr>\n";
  617.         }
  618.     } elsif ($terms{'hardware'} eq 'T1') {
  619.         print "<tr><td>Port:</td><td>$terms{'port'}</td></tr>\n";
  620.     } elsif (substr($terms{'hardware'},0,6) eq 'Ethern') {
  621.         print "<tr><td>Interface:</td><td>$outInterface</td></tr>\n";
  622.         print "<tr><td>IP address:</td><td>$terms{'address'}</td></tr>\n";
  623.         print "<tr><td>Netmask:</td><td>$terms{'netmask'}</td></tr>\n";
  624.     }
  625.  
  626.     print "</table></center><br>\n\n";
  627.  
  628.     printf("<form name=\"end\" action=\"%s\" method=post onSubmit=\"return runSubmit()\">\n", $myname);
  629.  
  630.     print "<input type=hidden name=prev value=$ARGV[0]>\n";
  631.  
  632.     print "<table width=630>";
  633.  
  634.     print "<tr><td width=50%>If the summary information is correct, select <I>Accept and 
  635.     Reboot</I> to configure and reboot the WebForce Internet Gateway. The 
  636.     Gateway will take four or five minutes to reboot and restart its network 
  637.     services. If the information that you entered on the setup forms is 
  638.     correct, you will be able to access the Internet when this process 
  639.     is complete. 
  640.     </td>";
  641.  
  642.     print "<td align=right valign=top><font size=5><i>\n";
  643.     print qq|<input type=submit name="accept" value="Accept"
  644.     onClick="markAccept()">\n|;
  645.     print "</i></font></td></tr>\n\n";
  646.  
  647.     print "<tr><td> </td></tr>\n";
  648.  
  649.     print "<tr><td>If you see an error in the summary information, select 
  650.     <I>Cancel</I> to delay the configuration and return to the first page 
  651.     of the Setup forms to correct your entries. Or, select <I>Previous</I> 
  652.     to return directly to the previous form.</td>";
  653.  
  654.     print "<td align=right valign=top><font size=5><i>\n";
  655.     print qq|<input type=submit name="cancel" value="Cancel" 
  656.     onClick="markCancel()">\n|;
  657.     print "</i></font></td></tr>\n\n";
  658.  
  659.     print "</table>\n";
  660.  
  661.     print '<MAP NAME="js_map1">',
  662.     '   <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()"
  663.     onMouseOver="window.status=\'\';return true">',
  664.     '</MAP>',
  665.     '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" ALIGN="right">';
  666.  
  667.     print "\n</form></body></html>";
  668. }
  669.  
  670. sub turnOffPort {
  671.     $nm = $_[0];
  672.  
  673.     undef @terms;
  674.     $terms[0] = 'wan0'.$nm;
  675.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  676.  
  677.     $terms[0] = 'wstyd0'.$nm;
  678.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  679.  
  680.     $terms[0] = 'wstyd0'.$nm;
  681.     $terms[1] = 'wan0'.$nm;
  682.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  683. }
  684.  
  685. sub turnOnPort {
  686.     $nm = $_[0];
  687.  
  688.     undef @terms;
  689.     $terms[0] = 'wan0'.$nm;
  690.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  691.     elsif (! &lookFor(0,$confW,*terms)) { 
  692.         &writeTop($confW,"wan0".$nm."\td\t\t/dev/gsc/wan0".$nm); 
  693.     }
  694.  
  695.     $terms[0] = 'wstyd0'.$nm;
  696.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  697.     elsif (! &lookFor(0,$confW,*terms)) { 
  698.         &writeTop($confW,"wstyd0".$nm."\t\td\t/dev/gsc/wstyd0".$nm); 
  699.     }
  700.  
  701.     $terms[0] = 'wstyd0'.$nm;
  702.     $terms[1] = 'wan0'.$nm;
  703.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  704.     elsif (! &lookFor(0,$confW,*terms)) {
  705.         if ($nm == 0) { $let = "D"; } else { $let = "E"; }
  706.         &writeBottom($confW,"$terms[0]\t\t$terms[1]\tWSYNCD_SNID=$let"); 
  707.     }
  708. }
  709.  
  710. sub writeTop {
  711.     local($file) = $_[0];
  712.     local($value) = $_[1];
  713.     $found = 0;
  714.     open(IN,"< $file");
  715.     open(OUT,"> $dummy");
  716.     while(<IN>) {
  717.         if ($_ eq "%%\n" && $found == 0) {
  718.             $found = 1;
  719.             print OUT "$value\n\n%%\n";
  720.         }
  721.         if ($_ eq "\n" && $found == 0) {
  722.             $found = 1; 
  723.             print OUT "\n$value\n";
  724.         } else { print OUT $_; }
  725.     }
  726.     close(IN);
  727.     close(OUT);
  728.     rename($dummy,$file);
  729. }            
  730.  
  731. sub writeBottom {
  732.     local($file) = $_[0];
  733.     local($value) = $_[1];
  734.     $found = 0;
  735.     open(IN,"< $file");
  736.     open(OUT,"> $dummy");
  737.     while(<IN>) {
  738.         if (substr($_,0,2) eq '%%' && $found == 0) {
  739.             print OUT "%%\n\n$value\n";
  740.             $found = 1;
  741.         } else { print OUT $_; }
  742.     }
  743.     if ($found == 0) { print OUT "$value\n"; }
  744.     close(IN);
  745.     close(OUT);
  746.     rename($dummy,$file);
  747. }
  748.    
  749. sub uncomment {
  750.     local($file) = $_[0];
  751.     local(*values) = @_[1];
  752.  
  753.     open(IN,"< $file");
  754.     open(OUT,"> $dummy");
  755.     $fix = "fix";
  756.  
  757.     while(<IN>) {
  758.         $line = $_;
  759.         if ($line eq "\n") { print OUT "\n"; next; }
  760.         $fix =~ /(fix)/;
  761.         $line =~ /^\s*\#\s*(\S.*)/;
  762.         $line1 = $1;
  763.         @items = split(/\s+/,$line1);
  764.         $chk = 1;
  765.         for ($ii=0;$ii<=$#values;$ii++) {
  766.             if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  767.         }
  768.         if ($chk) { print OUT "$line1\n"; }
  769.         else { print OUT $line; }
  770.     }
  771.     close(OUT);
  772.     close(IN);
  773.     rename($dummy,$file);
  774. }
  775.  
  776. sub comment {
  777.     $ret = 0;    
  778.     local($file) = $_[0];
  779.     local(*values) = @_[1];
  780.  
  781.     open(IN,"< $file");
  782.     open(OUT,"> $dummy");
  783.     while(<IN>) {
  784.         $line = $_;
  785.         if ($line eq "\n") { print OUT "\n"; next; }
  786.         @items = split(/\s+/,$line);
  787.         $chk = 1;
  788.         for ($ii=0;$ii<=$#values;$ii++) {
  789.             if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  790.         }
  791.         if ($chk) { print OUT "#$line"; $ret = 1; }
  792.         else { print OUT $line; }
  793.     }
  794.     close(OUT);
  795.     close(IN);
  796.     rename($dummy,$file);
  797.     return $ret;
  798. }
  799.  
  800. sub lookFor {
  801.     local($ii);
  802.     local($mode) = $_[0];
  803.     local($file) = $_[1];
  804.     local(*values) = @_[2];
  805.     open(IN,"< $file");
  806.     while(<IN>) {
  807.         $line = $_;
  808.         if ($mode == 1) {
  809.             $line =~ /^\s*\#\s*(\S.*)/;
  810.             $line1 = $1;
  811.         } else { $line1 = $line; }
  812.         @items = split(/\s+/,$line1);
  813.         $chk = 1;
  814.         for ($ii=0;$ii<=$#values;$ii++) {
  815.             if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  816.         }
  817.         if ($chk) { close(IN); return 1; }
  818.     }
  819.     close(IN);
  820.     return 0;
  821. }
  822.